/*
 * PopupAttachmentMsg.hpp
 *
 *  Created on: May 12, 2012
 *      Author: guillou
 */

#ifndef POPUPATTACHMENTMSG_HPP_
#define POPUPATTACHMENTMSG_HPP_

#include "PopupLibTypes.hpp"
#include "PopupAbstractMessage.hpp"
#include "PopupFileTransferExt.hpp"

namespace Popup
{
  struct AttachmentMsg : public AbstractMessage
  {
    enum
    {
      MSGID,
      TARGETS,
      ATTACHMENTID,
      TOTALSIZE,
      FILENAME,
      NBFRAMES,
      FRAMENO,
      FRAMESIZE,
      RAWDATA,
      CHECKSUM
    };

    //! Constructor used in order to send a message
    AttachmentMsg(const FileTransferExt *p_sendinfo)
      : AbstractMessage(POPUP_MSG_TYPE_ATTACHMENT), sendinfo(p_sendinfo),
        frameSize(POPUP_MACRO_MIN(p_sendinfo->nbRemaining,
                                  POPUP_MSG_SPLIT_SIZE)) {}

    //! Constructor used in order to receive a message
    AttachmentMsg(const Message *p_message);

    virtual ~AttachmentMsg() {}

    //!@Override
    bool onSend();

    //!@Override
    bool onReceive();

    const MessageID & getParentMessageID() const { return recvinfo.messageID; }
    const UserList & getTargets() const { return recvinfo.targets; }
    const AttachmentID & getAttachmentID() const { return recvinfo.attachmentID; }
    const std::string & getFilename() const { return recvinfo.filepath; }
    unsigned int  getTotalSize() const { return recvinfo.totalSize; }
    unsigned int  getNbFrames() const { return recvinfo.totalNbFrames; }
    unsigned int  getFrameNo() const { return recvinfo.frameNo; }
    unsigned short getFrameSize() const { return frameSize; }
    bool getRawData(PopupUtils::FileStream *p_file) const;
    unsigned long long getChecksum() const { return recvinfo.checksum; }

  private:
    const FileTransferExt *sendinfo;
    FileTransferExt recvinfo;
    unsigned int  frameSize;
  };
}

#endif /* POPUPATTACHMENTMSG_HPP_ */
